package com.zsc.spring.study.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import java.util.Arrays;


@Aspect
public class LogAspect {

	/**
	 * 切入点
	 */
	@Pointcut("execution(* com.rn.model.Calculater.*(..))")
	public void pointCut(){	}

	/**
	 * 前置通知
	 * @param jPoint
	 */
	@Before("pointCut()")
	public void logStart(JoinPoint jPoint){
		System.out.println(""+jPoint.getSignature().getName()+"运行。。。。参数列表是：{"+
		  Arrays.asList(jPoint.getArgs())+"}");
	}

	/**
	 * 后置通知
	 * @param jPoint
	 */
	@After("pointCut()")
	public void logEnd(JoinPoint jPoint){
		System.out.println(""+jPoint.getSignature().getName()+"结束。。。。@after");
	}

	/**
	 * 返回结果之后
	 * @param jPoint
	 * @param result
	 */
	@AfterReturning(value = "pointCut()",returning = "result")
	public void logReturn(JoinPoint jPoint,Object result){
		System.out.println(jPoint.getSignature().getName()+":正常返回....@AfterReturning"
				+ "���н��:{"+result+"}");
	}


	/**
	 * 异常通知
	 * @param jPoint
	 * @param exception
	 */
	@AfterThrowing(value = "pointCut()",throwing = "exception")
	public void logException(JoinPoint jPoint,Exception exception){
		System.out.println(jPoint.getSignature().getName()+":异常....异常信息：{"+exception+"}");
	}

	/**
	 * 环绕通知
	 * @param jp
	 * @throws Throwable
	 */
	@Around("pointCut()")
	public void logAround(ProceedingJoinPoint jp) throws Throwable{
		System.out.println("around before..");
		jp.proceed();
		System.out.println("around after...");
	}
	
}
